$(document).ready(function () {
    var currPage = 1;
    var pageSize = 2;
    var pageCount = 0;
    var name;
    function studentsViewAjax() {
        alert(name);
        $.ajax({
            url: 'student/searchStudentByName/'+name,
            type: 'post',
            data: {'currPage': currPage, 'pageSize': pageSize},
            dataType: 'json',
            success: function (dto) {
                if (dto.code == 200) {
                    $('.studentsViewUl > li:gt(0)').remove();//除了第一个li其余li删除
                    $('.studentsViewUl > li:first').css('display', 'block');
                    console.log(dto);
                    var $students = $(dto.tList);
                    $students.each(function (i, student) {
                        //利用模板中存在一行静态数据 通过clone 克隆方法得到复制对象，将复制对象修改后追加到父元素中
                        var $newli = $('.studentsViewUl > li:first').clone();
                        $newli.find('ul li').eq(0).children('img').attr('src', student.imgsrc);
                        $newli.find('ul li').eq(1).children('span').text(student.sno);
                        $newli.find('ul li').eq(2).children('span').text(student.name);
                        $newli.find('ul li').eq(3).children('span').text(student.sex);
                        $('.studentsViewUl').append($newli)//在元素的内部的尾部追加
                    });

                    $('.studentsViewUl > li:first').css('display', 'none');
                    $(".pageInfo").html('');
                    pageInfo = dto.obj;
                    $(".pageInfo").html('一共' + pageInfo.itemCount + '条,当前' + pageInfo.currPage + '/' + pageInfo.pageCount + '，页');
                } else {
                    alert(dto.msg);
                }
            }
        });

    }
    $('#search').click(function(){
        name = $('#searchName').val();
        studentsViewAjax();
    });

    $(".changePage").click(function(){
        alert($(this).attr("id"));
        if($(this).attr("id")=='prevPage'){
            currPage = currPage - 1;
        }else{
            currPage = currPage + 1;
        }
        studentsViewAjax();
    });
});